<!doctype html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>课表</title>
    <meta name="context-path" th:content="@{/}"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" th:href="@{/resources/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/resources/css/website.css}"/>
    <script th:src="@{/resources/time_table/index.js}"></script>
    <script th:src="@{/resources/js/jquery.min.js}"></script>
    <script th:src="@{/resources/js/jquery-migrate-1.2.1.js}"></script>
    <script th:src="@{/resources/jquery-easyui/jquery.easyui.min.js}"></script>
    <script th:src="@{/resources/layui/layui.all.js}" charset="utf-8"></script>
    <script th:src="@{/resources/valid/js/bootstrapValidator.js}"></script>
    <script th:src="@{/resources/valid/js/language/zh_CN.js}"></script>
    <script th:src="@{/resources/js/website.js}"></script>
    <script th:src="@{/resources/js/system.js}"></script>
    <script th:src="@{/resources/js/validation_fields.js}"></script>
    <style>
        #coursesTable {
            padding: 15px 10px;
        }

        .Courses-head {
            background-color: #edffff;
        }

        .Courses-head > div {
            text-align: center;
            font-size: 14px;
            line-height: 28px;
        }

        .left-hand-TextDom, .Courses-head {
            background-color: #f2f6f7;
        }

        .Courses-leftHand {
            background-color: #f2f6f7;
            font-size: 12px;
        }

        .Courses-leftHand .left-hand-index {
            color: #9c9c9c;
            margin-bottom: 4px !important;
        }

        .Courses-leftHand .left-hand-name {
            color: #666;
        }

        .Courses-leftHand p {
            text-align: center;
            font-weight: 900;
        }

        .Courses-head > div {
            border-left: none !important;
        }

        .Courses-leftHand > div {
            padding-top: 5px;
            text-align: center;

            border-bottom: 1px dashed rgb(219, 219, 219);
            writing-mode: vertical-lr;
            line-height: 50px;
            font-size: 16px;
            letter-spacing: 10px;
        }

        .Courses-leftHand > div:last-child {
            border-bottom: none !important;
        }

        .left-hand-TextDom, .Courses-head {
            border-bottom: 1px solid rgba(0, 0, 0, 0.1) !important;
        }

        .Courses-content > ul {
            border-bottom: 1px dashed rgb(219, 219, 219);
            box-sizing: border-box;
        }

        .Courses-content > ul:last-child {
            border-bottom: none !important;
        }

        .highlight-week {
            color: #02a9f5 !important;
        }

        .Courses-content li {
            text-align: center;
            color: #666666;
            font-size: 14px;
            line-height: 50px;
        }

        .Courses-content li span {
            padding: 6px 2px;
            box-sizing: border-box;
            line-height: 18px;
            border-radius: 4px;
            white-space: normal;
            word-break: break-all;
            cursor: pointer;
        }

        .grid-active {
            z-index: 9999;
        }

        .grid-active span {
            box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
        }
    </style>
</head>
<body>
<div id="coursesTable"></div>

<script th:inline="javascript">
    /*var courseList = [
        ['大学英语(Ⅳ)@10203', '大学英语(Ⅳ)@10203', '', '', '', '', '毛概@14208', '毛概@14208', '', '', '', '选修'],
        ['', '', '信号与系统@11302', '信号与系统@11302', '模拟电子技术基础@16204', '模拟电子技术基础@16204', '', '', '', '', '', ''],
        ['大学体育(Ⅳ)', '大学体育(Ⅳ)', '形势与政策(Ⅳ)@15208', '形势与政策(Ⅳ)@15208', '', '', '电路、信号与系统实验', '电路、信号与系统实验', '', '', '', ''],
        ['', '', '', '', '电装实习@11301', '电装实习@11301', '', '', '', '大学体育', '大学体育', ''],
        ['', '', '数据结构与算法分析', '数据结构与算法分析', '', '', '', '', '信号与系统', '信号与系统', '', ''],
    ];*/
    var timetable,editTable,addTable;

    var ListEditTable = function (layer, params) {
        var self = this;
        self.title = params.title;
        self.url = params.url;
        self.width = params.width;
        self.height = params.height;
        self.isfull = params.isfull ? true : false;
        self.layerIndex = null;
        self.openDialog = function (e) {
            self.layerIndex = layer.open({
                type: 2,
                title: self.title,
                shadeClose: true,
                skin: 'layui-layer-lan',
                offset: '20px',
                shade: 0.8,
                area: [self.width, self.height],
                content: self.url + "/" + e.id,
                maxmin: self.isfull
            });
            if (self.isfull == true) {
                layer.full(self.layerIndex);
            }
        }
        self.closeDialog = function () {
            layer.close(self.layerIndex);
        };
        self.editCompleted = function () {
            self.closeDialog();
            window.location.reload();
        }
    };

    var ListAddTable = function (layer, params) {
        var self = this;
        self.title = params.title;
        self.url = params.url;
        self.width = params.width;
        self.height = params.height;
        self.getUrl = params.getUrl;
        self.isfull = params.isfull ? true : false;
        self.layerIndex = null;
        self.openDialog = function (e,clazzId) {
            var tempUrl = self.url;
            if (self.getUrl) {
                tempUrl = self.getUrl(self.url);
            }
            self.layerIndex = layer.open({
                type: 2,
                title: self.title,
                shadeClose: true,
                skin: 'layui-layer-lan',
                shade: 0.8,
                offset: '20px',
                area: [self.width, self.height],
                content: self.url + "/" + e.id,
                content: tempUrl+"?clazzId="+clazzId+"&sorts="+e.index+"&day="+e.day,
            });
            if (self.isfull == true) {
                layer.full(self.layerIndex);
            }
        };
        self.closeDialog = function () {
            layer.close(self.layerIndex);
        };
        self.addCompleted = function () {
            self.closeDialog();
            window.location.reload();
        }
    };
    layui.use(['jquery', 'layer', 'laydate'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            table = layui.table;

        lay('.date').each(function () {
            laydate.render({
                elem: this
            });
        });



        var courseList = [[${tableArr}]];
        var clazzId = [[${clazzId}]];
        var week = window.innerWidth > 360 ? ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'] :
            ['1', '2', '3', '4', '5', '6', '7'];
        var day = new Date().getDay();

        var courseType = [
            ['上午', 4],
            ['下午', 4]
        ];
        // 实例化(初始化课表)
        timetable = new Timetables({
            el: '#coursesTable',
            timetables: courseList,
            week: week,
            timetableType: courseType,
            highlightWeek: day,
            gridOnClick: function (e) {
                console.log(e);
                /*alert(e.name + '  ' + e.week + ', 第' + e.index + '节课, 课长' + e.length + '节');*/
                if(null!=e.id){
                    editTable.openDialog(e);
                }else{
                    addTable.openDialog(e,clazzId);
                }

            },
            styles: {
                Gheight: 50
            }
        });
        timetable._init();

        editTable = new ListEditTable(layer, {
            title: "修改课程",
            url: contextRoot + "timeTableBack/getEdit",
            width: "600px",
            height: "400px"
        }, timetable);

        addTable = new ListAddTable(layer, {
            title: "添加课程",
            url: contextRoot + "timeTableBack/getAdd",
            width: "600px",
            height: "400px"
        }, timetable);
    });
</script>
</body>
</html>
